package com.neusoft.yuejian_01.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.yuejian_01.activity.MatchDetailActivity;
import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.base.BaseAdapter;
import com.neusoft.yuejian_01.javabean.MatchBean;
import com.neusoft.yuejian_01.model.ConstPhoto;
import com.neusoft.yuejian_01.viewHolder.MatchViewHolder;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;

/**
 * Created by Administrator on 2017/10/2.
 */

public class MatchAdapter extends BaseAdapter {
    public MatchAdapter(Context context, List data) {
        super(context, data);
    }

    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_matchlist,parent,false);
        MatchViewHolder viewHolder = new MatchViewHolder(itemView);
        return viewHolder;
    }

    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        MatchBean matchlist = (MatchBean) data.get(position);
        MatchViewHolder viewHolder = (MatchViewHolder) holder;
        String matchName = matchlist.getM_name();
        final int m_id = matchlist.getM_id();
        viewHolder.matchView.setText(matchName);
        String matchImage = ConstPhoto.BASE_URL+ConstPhoto.MatchFile+ matchlist.getM_picture();
        Picasso.with(context)
                .load(matchImage)
                .placeholder(R.drawable.pic2)
                .into(viewHolder.matchImage);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的activity(比赛列表)
                Intent intent = new Intent(context, MatchDetailActivity.class);
                intent.putExtra("m_id", m_id);
                context.startActivity(intent);
            }
        });
    }
    }

